package part16;

import java.util.Arrays;
import java.util.Random;

/**
 * @author wcj
 * @Date 2021/5/31 16:46
 * @Version 1.0
 */
public class Part163 {

    private static Random random = new Random(47);
    private static final String[] FLOWERS = {"MeiGui", "JuHua", "TaoHua", "XiangRiKui", "CaiHua", "XiaoHua"};

    /**
     * 方法返回数组和正常的返回没有什么不同
     *
     * @param n
     * @return
     */
    public static String[] flowersSet(int n) {
        if (n > FLOWERS.length) {
            throw new RuntimeException("Set to big");
        }
        String[] result = new String[n];
        boolean[] picked = new boolean[FLOWERS.length];
        for (int i = 0; i < n; i++) {
            int t;
            do {
                t = random.nextInt(FLOWERS.length);
            } while (picked[t]);
            result[i] = FLOWERS[t];
            picked[t] = true;
        }
        return result;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 7; i++) {
            System.out.println(Arrays.toString(flowersSet(i)));
        }
    }
}
